<?php
 session_start();
require_once("bdd.php");

if( isset($_POST['valider']) || isset($_POST['supprimer'])  ) {


if( isset($_POST['valider']) ) {

	$valids = $_POST['valider'];
} else {
	$valids = Array();
}

if( isset($_POST['supprimer']) ) {

	$supprims = $_POST['supprimer'];
} else {
	$supprims = Array();
}


	
    foreach($valids as $selectValue){	
		$ok = true;
		foreach($supprims as $selectValue2){
	
			if($selectValue == $selectValue2) 
				$ok = false;
		}
		if($ok) {
			//
			if( isset($_POST['role'.$selectValue]) ) {
				$connexion->exec("UPDATE user SET valide='1' WHERE iduser=".$selectValue."");
				$connexion->exec("UPDATE user SET droit=".$_POST['role'.$selectValue]." WHERE iduser=".$selectValue."");
			}
		}
		
	}
	
	
	foreach($supprims as $selectValue){	
		$ok = true;
		foreach($valids as $selectValue2){
	
			if($selectValue == $selectValue2) 
				$ok = false;
		}
		if($ok)
			$connexion->exec("DELETE FROM user WHERE iduser=".$selectValue."");
		
	}
	
	
	$i=0;	
			
					 $hostAccueil  = $_SERVER['HTTP_HOST'];
					 $url = '/compte.php?msg=1';
					header("Location: http://$hostAccueil$url");
} else {

	 $hostAccueil  = $_SERVER['HTTP_HOST'];
	  $url = '/compte.php';
 header("Location: http://$hostAccueil$url");

}
?>